package com.xxl.job.executor.structure;

import java.util.Stack;

/**
 * 递归反转栈
 */
public class ReverseStackByRecursion {

    public static int reverseStack(Stack<Integer> st){

        int result = st.pop();
        if(st.isEmpty()){
            return result;
        }
        int last = reverseStack(st);
        st.push(result);
        return last;

    }

    public static void getReverse(Stack<Integer> st){
        if(st.isEmpty()){
            return;
        }
        int i = reverseStack(st);
        getReverse(st);
        st.push(i);
    }

    public static void main(String[] args) {
        Stack<Integer> is = new Stack<>();
        is.push(1);
        is.push(2);
        is.push(3);
        is.push(4);
        getReverse(is);
        System.out.println(is.peek());
    }
}
